package com.zwh.rabbitmq.module.project;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zwh
 * @date 2021/12/8 9:28
 **/
@Configuration
public class ProjectMqConfig {

    /**
     * 合同或项目交换机
     * @return
     */
    @Bean
    public DirectExchange projectDirectExchange(){
        DirectExchange directExchange=new DirectExchange(ProjectMqConstants.CONTRACT_OR_PROJECT_EXCHANGE);
        return directExchange;
    }
    /**
     * 项目（新增/修改）事件队列
     *
     * @return
     */
    @Bean
    public Queue projectAddOrUpdateQueue() {
        return new Queue(ProjectMqConstants.PROJECT_ADD_QUEUE);
    }

    /**
     * 项目（新增/修改）事件队列 绑定路由
     * @return
     */
    @Bean
    public Binding projectAddOrUpdateQueueBinding(){
        return BindingBuilder.bind(projectAddOrUpdateQueue()).to(projectDirectExchange())
                .with(ProjectMqConstants.PROJECT_ADD_QUEUE);
    }

    /**
     * 项目删除事件队列
     *
     * @return
     */
    @Bean
    public Queue projectDeleteQueue() {
        return new Queue(ProjectMqConstants.PROJECT_DELETE_QUEUE);
    }

    /**
     * 项目删除事件队列 绑定路由
     * @return
     */
    @Bean
    public Binding projectDeleteQueueBinding(){
        return BindingBuilder.bind(projectDeleteQueue()).to(projectDirectExchange())
                .with(ProjectMqConstants.PROJECT_DELETE_QUEUE);
    }
}
